import json
import requests
import re


def get(msg):
    # 正则匹配需要查找的词
    pattern = re.compile(r'(.+)的天气')
    keyWord = pattern.findall(msg)[0]
    # 调用查询天气API
    response = requests.get(
        url='http://wthrcdn.etouch.cn/weather_mini?city=' + keyWord)
    result = json.loads(response.text)
    # 解析json
    data = result["data"]["forecast"][0]["date"]
    high = result["data"]["forecast"][0]["high"]
    fengli = result["data"]["forecast"][0]["fengli"]
    low = result["data"]["forecast"][0]["low"]
    fengxiang = result["data"]["forecast"][0]["fengxiang"]
    tian = result["data"]["forecast"][0]["type"]
    return "时间：" + data + "\n最好气温：" + high + "\n最低气温：" + low + "\n风向：" + fengxiang + "\n天气：" + tian
